package impl;


import components.QuasiComponentLifeCycle;



	
import engine.AlternateStateThreadPoolExecutor;

	public class LifeCycleImpl extends QuasiComponentLifeCycle{

		private boolean alive = true;

		public void start() {
			cycle();
		}
		
		private void cycle(){
			Runnable me = new Runnable() {
				public void run() {
					//System.out.println(" step S");
					  cycle((Message)getMessage());
				    //System.out.println("step S fin");				
					if(alive) LifeCycleImpl.this.cycle();
				}
			};
		AlternateStateThreadPoolExecutor.processExe.execute(me);
		}


//  private final ExecutorService executor;
//  private Future<?> currentTask;
//  private boolean run = true;
//  
//  public LifeCycleImpl(ExecutorService e) {
//    executor = e;
//  }
  
//  public void start() {
//    if (run) {
//      currentTask = executor.submit(new Runnable() {
//        public void run() {
//       // System.out.println("dans run de start");
//          LifeCycleImpl.this.step();
//          LifeCycleImpl.this.start();
//         // System.out.println("start fin");
//        }
//      });
//    } else {
//      System.out.println(": aaaaaaa");
//    }
//  }
  
  
  protected void step() {
	// TODO Auto-generated m//System.out.println(architecture().me()+" step S");
		  cycle((Message)getMessage());
		  //cycle(null);
	    //System.out.println("step S fin");ethod stub
		  

}

@Override
  public void stopLifecycle() {
    alive=false;
  }
}
